﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using KinnectInput.KinectVideo;


using KinnectInput.KinectIcons;
//Tengo que usar un alias porque sino colisiona
using jupLib = JupiterLibrary;

namespace KinnectInput
{
    public class Animation
    {
        public Microsoft.Xna.Framework.Media.VideoPlayer myPlayer { get; private set; }
        public Microsoft.Xna.Framework.Media.Video movie { get; private set; }
        Rectangle imageSize;
        jupLib.Sprite NoVideo;
        jupLib.Sprite VideoDisplay;
        public KinectVideoPlayerState AnimationDisplayState;

        public Animation(Video movie, Rectangle imageSizeRect)
        {
            this.movie = movie;
            myPlayer = new VideoPlayer();
            this.imageSize = imageSizeRect;
            BuildPlayer(imageSizeRect);
            AnimationDisplayState = KinectVideoPlayerState.Colasped;
        }
        private void BuildPlayer(Rectangle imageSizeRect)
        {
            VideoDisplay = new jupLib.Sprite();
            VideoDisplay.SetRectangle(imageSizeRect);

            NoVideo = new jupLib.Sprite();
            NoVideo.SetRectangle(imageSizeRect);
            NoVideo.SetColor(new Color(0, 0, 0.25f, 0.9f));
            NoVideo.Update();

        }
        public void Update()
        {
            if (myPlayer != null && movie != null) 
            {
                if (myPlayer.State == MediaState.Playing)
                {
                    VideoDisplay.Texture = myPlayer.GetTexture();
                }
                if (myPlayer.PlayPosition == movie.Duration)
                {
                    myPlayer.Stop();
                }
            }
            

            VideoDisplay.Update();
        }
        public void Draw()
        {
            if (AnimationDisplayState == KinectVideoPlayerState.Visible)
            {
                if (myPlayer.State == MediaState.Playing)
                {
                    VideoDisplay.Draw();
                }
                
            }
        }
    }
}
